<!DOCTYPE html>
<html lang="en-us">
  <head>
  <meta http-equiv="content-type" content="text/html;charset=utf-8">
  <meta http-equiv="X-UA-Compatible" content="chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="robots" content="noodp"/>
  <meta name="author" content="Mr.wei">
  
  
  
  <link rel="prev" href="http://blog.mr-wei.cn/2019/nrf52840%E4%BD%9Ccentral%E4%B9%8B%E8%BF%9E%E6%8E%A5%E6%8C%87%E5%AE%9A%E5%A4%96%E8%AE%BE/" />
  <link rel="next" href="http://blog.mr-wei.cn/2019/cadence-allegro-%E4%B8%9D%E5%8D%B0%E5%AD%97%E4%BD%93/" />
  <link rel="canonical" href="http://blog.mr-wei.cn/2019/nrf52840%E4%BE%8B%E7%A8%8B%E4%BD%93%E9%AA%8C%E4%B9%8Bdfu/" />
  <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
  <link rel="manifest" href="/site.webmanifest">
  <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
  <meta name="msapplication-TileColor" content="#da532c">
  <meta name="theme-color" content="#ffffff">
  <title>
       
       
           NRF52840例程体验之DFU | Mr.wei
       
  </title>
  <meta name="title" content="NRF52840例程体验之DFU | Mr.wei">
    
  
  <link rel="stylesheet" href="/font/iconfont.css">
  <link rel="stylesheet" href="/css/main.min.css">


  
  
 

<script type="application/ld+json">
 "@context" : "http://schema.org",
    "@type" : "BlogPosting",
    "mainEntityOfPage": {
         "@type": "WebPage",
         "@id": "http:\/\/blog.mr-wei.cn"
    },
    "articleSection" : "posts",
    "name" : "NRF52840例程体验之DFU",
    "headline" : "NRF52840例程体验之DFU",
    "description" : "环境  HOST：Windows 10 LTSC SDK：nRF5_SDK_15.2.0 相关软件：  MDK5.25  ARM.CMSIS.4.5.0 NordicSemiconductor.nRF_DeviceFamilyPack.8.17.0  nrfgoStudio nrfutil nRF Connect for Desktop  相关硬件  nRF52840-Dongle nRF52840-DK    准备工作  安装相关的软件 将nrf5 Command Line Tools 的目录添加到系统环境变量，例如C:\\Program Files (x86)\\Nordic Semiconductor\\nrf5x\\bin 将nrfutil.exe文件放入C:\\Program Files (x86)\\Nordic Semiconductor\\nrf5x\\bin目录下  体验BLE DFU 准备工作  使用micro-usb线链接DK和PC 使用nrfjprog软件擦除DK上的所有程序\nnrfjprog -f NRF52 --eraseall  使用nrfutil工具生成密钥\nnrfutil.exe keys generate private.pem nrfutil.exe keys display --key pk --format code private.pem --out_file dfu_public_key.c\t 打开工程examples\\dfu\\secure_bootloader\\pca10056_ble_debug\\arm5_no_packs",
    "inLanguage" : "en-us",
    "author" : "Mr.wei",
    "creator" : "Mr.wei",
    "publisher": "Mr.wei",
    "accountablePerson" : "Mr.wei",
    "copyrightHolder" : "Mr.wei",
    "copyrightYear" : "2019",
    "datePublished": "2019-09-03 10:07:35 \x2b0800 CST",
    "dateModified" : "2019-09-03 10:07:35 \x2b0800 CST",
    "url" : "http:\/\/blog.mr-wei.cn\/2019\/nrf52840%E4%BE%8B%E7%A8%8B%E4%BD%93%E9%AA%8C%E4%B9%8Bdfu\/",
    "wordCount" : "193",
    "keywords" : [ "NRF52840", "Mr.wei"]
}
</script>

</head>

  


  <body class="">
    <div class="wrapper">
        <nav class="navbar">
    <div class="container">
        <div class="navbar-header header-logo">
        	<a href="javascript:void(0);" class="theme-switch"><i class="iconfont icon-xihuan"></i></a>&nbsp;<a href="http://blog.mr-wei.cn">Mr.wei</a>
        </div>
        <div class="menu navbar-right">
                
                
                <a class="menu-item" href="/posts/" title="">Blog</a>
                
                <a class="menu-item" href="http://balance.mr-wei.cn" title="">BalanceCar</a>
                
                <a class="menu-item" href="/categories/" title="">Categories</a>
                
                <a class="menu-item" href="/tags/" title="">Tags</a>
                
                <a class="menu-item" href="/about/" title="About">About</a>
                
        </div>
    </div>
</nav>
<nav class="navbar-mobile" id="nav-mobile" style="display: none">
     <div class="container">
        <div class="navbar-header">
            <div>  <a href="javascript:void(0);" class="theme-switch"><i class="iconfont icon-xihuan"></i></a>&nbsp;<a href="http://blog.mr-wei.cn">Mr.wei</a></div>
            <div class="menu-toggle">
                <span></span><span></span><span></span>
            </div>
        </div>
     
          <div class="menu" id="mobile-menu">
                
                
                <a class="menu-item" href="/posts/" title="">Blog</a>
                
                <a class="menu-item" href="http://balance.mr-wei.cn" title="">BalanceCar</a>
                
                <a class="menu-item" href="/categories/" title="">Categories</a>
                
                <a class="menu-item" href="/tags/" title="">Tags</a>
                
                <a class="menu-item" href="/about/" title="About">About</a>
                
        </div>
    </div>
</nav>







    	 <main class="main">
          <div class="container">
      		
<article class="post-warp" itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
        <h1 class="post-title" itemprop="name headline">NRF52840例程体验之DFU</h1>
        <div class="post-meta">
                Written by <a itemprop="name" href="http://blog.mr-wei.cn" rel="author">Mr.wei</a> with ♥ 
                <span class="post-time">
                on <time datetime=2019-09-03 itemprop="datePublished">September 3, 2019</time>
                </span>
                in
                <i class="iconfont icon-folder"></i>
                <span class="post-category">
                        
                </span>
        </div>
    </header>
    <div class="post-content">
        

        
            
        

        
        
     
          
          
          

          
          
          

          

<h1 id="环境">环境</h1>

<ul>
<li>HOST：Windows 10 LTSC</li>
<li>SDK：<a href="https://www.nordicsemi.com/Software-and-Tools/Software/nRF5-SDK/Download#infotabs" rel="nofollow noreferrer" target="_blank">nRF5_SDK_15.2.0</a></li>
<li>相关软件：

<ul>
<li><a href="http://www.keil.com/update/rvmdk.asp" rel="nofollow noreferrer" target="_blank">MDK5.25</a>

<ul>
<li><a href="https://www.keil.com/dd2/Pack/" rel="nofollow noreferrer" target="_blank">ARM.CMSIS.4.5.0</a></li>
<li><a href="https://www.keil.com/dd2/Pack/" rel="nofollow noreferrer" target="_blank">NordicSemiconductor.nRF_DeviceFamilyPack.8.17.0</a></li>
</ul></li>
<li><a href="https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRFgo-Studio/Download" rel="nofollow noreferrer" target="_blank">nrfgoStudio</a></li>
<li><a href="https://github.com/NordicSemiconductor/pc-nrfutil/releases/tag/v4.0.0" rel="nofollow noreferrer" target="_blank">nrfutil</a></li>
<li><a href="https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Connect-for-desktop/Download#infotabs" rel="nofollow noreferrer" target="_blank">nRF Connect for Desktop</a></li>
</ul></li>
<li>相关硬件

<ul>
<li>nRF52840-Dongle</li>
<li>nRF52840-DK
<!-- more --></li>
</ul></li>
</ul>

<h1 id="准备工作">准备工作</h1>

<ol>
<li>安装相关的软件</li>
<li>将nrf5 Command Line Tools 的目录添加到系统环境变量，例如C:\Program Files (x86)\Nordic Semiconductor\nrf5x\bin</li>
<li>将nrfutil.exe文件放入C:\Program Files (x86)\Nordic Semiconductor\nrf5x\bin目录下</li>
</ol>

<h1 id="体验ble-dfu">体验BLE DFU</h1>

<h1 id="准备工作-1">准备工作</h1>

<ol>
<li>使用micro-usb线链接DK和PC</li>

<li><p>使用nrfjprog软件擦除DK上的所有程序</p>

<pre><code class="language-shell">nrfjprog -f NRF52 --eraseall
</code></pre></li>

<li><p>使用nrfutil工具生成密钥</p>

<pre><code class="language-shell">nrfutil.exe keys generate private.pem
nrfutil.exe keys display --key pk --format code private.pem --out_file dfu_public_key.c	
</code></pre></li>

<li><p>打开工程examples\dfu\secure_bootloader\pca10056_ble_debug\arm5_no_packs</p></li>

<li><p>编译</p></li>

<li><p>打开工程examples\ble_peripheral\ble_app_buttonless_dfu\pca10056\s140\arm5_no_packs</p></li>

<li><p>编译</p></li>

<li><p>建立hex文件夹用于处理生成的文件</p></li>

<li><p>拷贝相关文件到8中建立的文件夹下</p>

<ol>
<li>examples\ble_peripheral\ble_app_buttonless_dfu\pca10056\s140\arm5_no_packs_build下的nrf52840_xxaa.hex并重命名为app.hex</li>
<li>components\softdevice\s140\hex下的s140_nrf52_6.1.0.softdevice.hex并重命名为softdevice.hex</li>
<li>examples\dfu\secure_bootloader\pca10056_ble_debug\arm5_no_packs_build下的nrf52840_xxaa_s140.hex并重命名为bootloader.hex</li>
<li>3中生成的private.pem
<br /></li>
</ol></li>

<li><p>生成设置信息</p>

<pre><code class="language-shell">nrfutil.exe settings generate --family NRF52840 --application app.hex --application-version 1 --bootloader-version 1 --bl-settings-version 1 settings.hex
</code></pre></li>

<li><p>生成更新包</p>

<pre><code class="language-shell">nrfutil pkg generate --hw-version 52 --sd-req 0xAE --application-version 0x04 --application app.hex --key-file private.pem app_v4.zip
</code></pre></li>

<li><p>将hex文件中的文件下载到DK中</p>

<ul>
<li><p>使用独立hex文件</p>

<pre><code class="language-shell">nrfjprog -f NRF52 --program &quot;softdevice.hex&quot; --verify 
nrfjprog -f NRF52 --program &quot;settings.hex&quot; --verify 
nrfjprog -f NRF52 --program &quot;bootloader.hex&quot; --verify
nrfjprog -f NRF52 --program &quot;app.hex&quot; --verify
nrfjprog -f NRF52 --reset
</code></pre></li>

<li><p>合并hex文件</p>

<pre><code class="language-shell">mergehex -m softdevice.hex bootloader.hex app.hex -o temporary.hex
mergehex -m temporary.hex settings.hex -o final.hex
nrfjprog -f NRF52 --program &quot;final.hex&quot; --verify
nrfjprog -f NRF52 --reset
</code></pre></li>
</ul></li>

<li><p>使用nRF Connect扫描并连接Nordic_Buttonless外设
<figure><img src="/images/ring.svg" data-sizes="auto" data-src="http://pan.mr-wei.cn/image/Blog_image/NRF52840%E4%BE%8B%E7%A8%8B%E4%BD%93%E9%AA%8C%E4%B9%8BDFU/14-11-46.png" alt="" class="lazyload"><figcaption class="image-caption"></figcaption></figure></p></li>

<li><p>点击DFU更新选择要更新的zip
<figure><img src="/images/ring.svg" data-sizes="auto" data-src="http://pan.mr-wei.cn/image/Blog_image/NRF52840%E4%BE%8B%E7%A8%8B%E4%BD%93%E9%AA%8C%E4%B9%8BDFU/13-54-44.png" alt="" class="lazyload"><figcaption class="image-caption"></figcaption></figure>
<figure><img src="/images/ring.svg" data-sizes="auto" data-src="http://pan.mr-wei.cn/image/Blog_image/NRF52840%E4%BE%8B%E7%A8%8B%E4%BD%93%E9%AA%8C%E4%B9%8BDFU/14-8-54.png" alt="" class="lazyload"><figcaption class="image-caption"></figcaption></figure>
<figure><img src="/images/ring.svg" data-sizes="auto" data-src="http://pan.mr-wei.cn/image/Blog_image/NRF52840%E4%BE%8B%E7%A8%8B%E4%BD%93%E9%AA%8C%E4%B9%8BDFU/14-9-49.png" alt="" class="lazyload"><figcaption class="image-caption"></figcaption></figure></p></li>

<li><p>完成更新再次扫描
<figure><img src="/images/ring.svg" data-sizes="auto" data-src="http://pan.mr-wei.cn/image/Blog_image/NRF52840%E4%BE%8B%E7%A8%8B%E4%BD%93%E9%AA%8C%E4%B9%8BDFU/14-11-46.png" alt="" class="lazyload"><figcaption class="image-caption"></figcaption></figure></p></li>
</ol>

<h1 id="体验uart-dfu">体验UART DFU</h1>

<ol>
<li>打开工程examples\dfu\secure_bootloader\pca10056_uart_debug\arm5_no_packs</li>
<li>编译</li>
<li>打开工程\examples\ble_peripheral\ble_app_blinky\pca10056\s140\arm5_no_packs</li>
<li>编译</li>
<li>将生成的hex文件复制到新建的HEX文件夹</li>
<li>参考BLE DFU 10、11、12生成相应文件</li>
<li>将hex下载到DK中</li>
<li>复位后使用nRF Connect 扫描到Nordic_Blinky外设</li>
<li>保持Button4 按键按下同时复位 DK,DK进入boot状态,LED1和LED3常量</li>

<li><p>串口升级</p>

<pre><code class="language-shell">nrfutil dfu serial -pkg app_v4.zip -p COM3
</code></pre></li>
</ol>

<h1 id="参考资料">参考资料</h1>

<ul>
<li><font size=6><a href="https://github.com/NordicSemiconductor/pc-nrfutil" rel="nofollow noreferrer" target="_blank">nrfutil使用</a></font></li>
<li><font size=6><a href="https://devzone.nordicsemi.com/b/blog/posts/getting-started-with-nordics-secure-dfu-bootloader" rel="nofollow noreferrer" target="_blank">Getting started with Nordic&rsquo;s Secure DFU bootloader, a step by step guide</a></font></li>
</ul>

    </div>

    <div class="post-copyright">
             
            <p class="copyright-item">
                <span>Author:</span>
                <span>Mr.wei </span>
                </p>
            
           
             
            <p class="copyright-item">
                    <span>Link:</span>
                    <a href=http://blog.mr-wei.cn/2019/nrf52840%E4%BE%8B%E7%A8%8B%E4%BD%93%E9%AA%8C%E4%B9%8Bdfu/>http://blog.mr-wei.cn/2019/nrf52840%E4%BE%8B%E7%A8%8B%E4%BD%93%E9%AA%8C%E4%B9%8Bdfu/</span>
            </p>
            
             
            <p class="copyright-item lincese">
                本文采用<a rel="license" href="http://creativecommons.org/licenses/by-nc/4.0/" #target="_blank">知识共享署名-非商业性使用 4.0 国际许可协议</a>进行许可
            </p>
            
    </div>

  
    <div class="post-tags">
        
            <section>
            <i class="iconfont icon-tag"></i>Tag(s): 
            
            <span class="tag"><a href="http://blog.mr-wei.cn/tags/nrf52840/">
                    #NRF52840</a></span>
            
            </section>
        
        <section>
                <a href="javascript:window.history.back();">back</a></span> · 
                <span><a href="http://blog.mr-wei.cn">home</a></span>
        </section>
    </div>

    <div class="post-nav">
        
        <a href="http://blog.mr-wei.cn/2019/nrf52840%E4%BD%9Ccentral%E4%B9%8B%E8%BF%9E%E6%8E%A5%E6%8C%87%E5%AE%9A%E5%A4%96%E8%AE%BE/" class="prev" rel="prev" title="NRF52840作Central之连接指定外设"><i class="iconfont icon-left"></i>&nbsp;NRF52840作Central之连接指定外设</a>
         
        
        <a href="http://blog.mr-wei.cn/2019/cadence-allegro-%E4%B8%9D%E5%8D%B0%E5%AD%97%E4%BD%93/" class="next" rel="next" title="Cadence Allegro 丝印字体">Cadence Allegro 丝印字体&nbsp;<i class="iconfont icon-right"></i></a>
        
    </div>

    <div class="post-comment">
          
                 
          
    </div>
</article>
          </div>
		   </main>
      <footer class="footer">
    <div class="copyright">
        &copy;
        
        <span itemprop="copyrightYear">2018 - 2019</span>
        
        <span class="with-love">
    	 <i class="iconfont icon-love"></i> 
         </span>
         
            <span class="author" itemprop="copyrightHolder"><a href="http://blog.mr-wei.cn">Mr.wei</a> | </span> 
         

         
            <a href="http://www.miibeian.gov.cn/" target="_blank" rel="external nofollow">冀ICP备 - 18032379号 </a> |
         
		  <span>Powered by <a href="https://gohugo.io/" target="_blank" rel="external nofollow">Hugo</a> & <a href="https://github.com/liuzc/leaveit" target="_blank" rel="external nofollow">LeaveIt</a></span> 
    </div>

	
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [['$','$'], ['\\(','\\)']],
            displayMath: [['$$','$$'], ['\[','\]']],
            processEscapes: true,
            processEnvironments: true,
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre'],
            TeX: {
                equationNumbers: { autoNumber: "AMS" },
                extensions: ["AMSmath.js", "AMSsymbols.js"]
            }
        }
    });
</script>
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML"></script>
	
	

</footer>












    
     <link href="//lib.baomitu.com/lightgallery/1.6.11/css/lightgallery.min.css" rel="stylesheet">  
      
     <script src="/js/vendor_gallery.min.js" async="" ></script>
    
  



     </div>
  </body>
</html>
